/*
 *  MutaSim - an artificial life simulator based on cellular automata.
 *  Copyright (C) 2009-2010 Alexei Tereschenko <aytereschenko@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tilex.sim;

import java.awt.*;
import javax.swing.*;


public class MutaSim extends JFrame {

	private static final long	serialVersionUID	= 5962566642196102920L;
	private SimPanel			simPanel			= null;

//	private Field				field				= null;
//	private JPanel				panel2				= null;
//	private JLabel				label1				= null;
//	private JLabel				label2				= null;
//	private JLabel				label3				= null;

	public MutaSim(String title) {
		super(title);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setResizable(false);
		Container c = getContentPane();
		simPanel = new SimPanel();
		simPanel.initializeField(80, 80, 3);
		simPanel.getField().setEdgeType(1);
		simPanel.setFieldVisualProperties(6, 1, 5);
		simPanel.setUpdateDelay(10);
		add(simPanel, BorderLayout.CENTER);
/*
		panel2 = new JPanel();
		panel2.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
		Dimension dim;
		label1 = new JLabel("Label1: test");
//		dim = label1.getPreferredSize();
//		dim.setSize(dim.getWidth() * 2, dim.getHeight() + 4);
//		label1.setPreferredSize(dim);
		label1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		label2 = new JLabel("Label2: test");
//		dim = label2.getPreferredSize();
//		dim.setSize(dim.getWidth() * 2, dim.getHeight() + 4);
//		label2.setPreferredSize(dim);
		label2.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		label3 = new JLabel("Label3: test");
//		dim = label3.getPreferredSize();
//		dim.setSize(dim.getWidth() * 2, dim.getHeight() + 4);
//		label3.setPreferredSize(dim);
		label3.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
		panel2.add(label1);
		panel2.add(label2);
		panel2.add(label3);
		add(panel2, BorderLayout.SOUTH);
*/
		pack();
		setVisible(true);

		CreatureSample s1 = new CreatureSample();
		s1.setColor(10);
		s1.setMutantColor(12);
		s1.setStartMass(1);
		s1.setResourceEat(1);
		s1.setReproductAge(5);
		s1.setMaxAge(10);
		s1.setChildrenCount(2);
		s1.setMutation(0);
		s1.setResourceIn(0);
		s1.setResourceOut(1);
		simPanel.getField().addCreature(40, 15, s1);

		CreatureSample s2 = new CreatureSample();
		s2.setColor(12);
		s2.setMutantColor(12);
		s2.setStartMass(1);
		s2.setResourceEat(1);
		s2.setReproductAge(5);
		s2.setMaxAge(10);
		s2.setChildrenCount(1);
		s2.setMutation(0);
		s2.setResourceIn(1);
		s2.setResourceOut(2);
		simPanel.getField().addCreature(18, 55, s2);

		CreatureSample s3 = new CreatureSample();
		s3.setColor(1);
		s3.setMutantColor(12);
		s3.setStartMass(1);
		s3.setResourceEat(1);
		s3.setReproductAge(5);
		s3.setMaxAge(10);
		s3.setChildrenCount(3);
		s3.setMutation(0);
		s3.setResourceIn(2);
		s3.setResourceOut(0);
		simPanel.getField().addCreature(64, 55, s3);
		simPanel.startSimulation();
	}

/*
	public void updateResourceCounters() {
		String rt = "";
		int sum = 0;
		for (int j = 0; j < field.getResourceTypes(); j++) {
			int r = field.getResourceCount(j);
			sum += r;
			rt += "[" + j + "]=" + r + ",";
		}
		int csum = field.getTotalCreatureMass();
		final String frt = rt;
		final int fsum = sum;
		final int fcsum = csum;
		SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				label1.setText("Resources: " + frt);
				label2.setText("Creatures: " + fcsum);
				label3.setText("Total: " + (fsum + fcsum));
			}
		});
	}
*/

	public static void main(String[] args) throws InterruptedException {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {}

		SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				new MutaSim("MutaSim");
			}
		});
	}
}
